import { _decorator, Component, director, Node, Scheduler, UITransform, Vec2 } from 'cc';
import { StateDefine } from '../../Config';
import { Enemy } from '../Enemy';
import { EnemyState } from '../EnemyState';
import { Enemy_Skeleton } from './Enemy_Skeleton';
const { ccclass, property } = _decorator;

@ccclass('SkeletonStunnedState')
export class SkeletonStunnedState extends EnemyState {
    protected enemy:Enemy_Skeleton;
    constructor(name: StateDefine, _enemy: Enemy_Skeleton, anim: StateDefine) {
        super(name, _enemy, anim);
        this.enemy = _enemy;
    }
    onEnter() {
        super.onEnter();
        this.enemy.fx.schedule(this.enemy.fx.RedColorBlink,0.1)
        this.stateTime = this.enemy.stunDuration;
        this.rb.linearVelocity = new Vec2(this.enemy.stunDirection.x*-this.enemy.facingDir,this.enemy.stunDirection.y);
        
    }
    onExit() {
        super.onExit();
        this.enemy.fx.CancelRedBlink();
    }
    update(deltaTime: number) {
        
        super.update(deltaTime);
        if(this.stateTime<0)this.enemy.stateMgr.transit(StateDefine.SkeletonIdle);
    }
    onDestory() { }
    canTransit(to: StateDefine): boolean {
        if(this.stateTime>0) return false;
        return true;
    }
        
    
}


